/*
 * @(#)CtrlOptimizacion.java 1.50 13/11/13
 * 
 * Clase Compartida
 * PROP Grupo 13 Cluster 3
 */


/**
 * Implementaci�n de la clase que controla las llamadas que se realizan para optimizar el coste tanto de Tareas como de SubTareas.
 * Desde aqu� se accede a ambos algoritmos compartidos.
 * 
 * @author Anna Lopez Mora
 */
package dominio;

import java.util.ArrayList;

import controladoresdominio.CtrlConfiguracion;
import test.Testing;



public class CtrlOptimizacion {
	//private Christophides cf;
	CtrlConfiguracion conf;
	int coste_inicial = 0;
	
	public int getCoste_inicial() {
		return coste_inicial;
	}

	public void setCoste_inicial(int coste_inicial) {
		this.coste_inicial = coste_inicial;
	}

	public CtrlOptimizacion(CtrlConfiguracion conf) {
		this.conf = conf; 
	}
	
	public Graph optimizar_tarea(Graph graph) {
        PathOptimizationResult optimized;
        PathOptimizationResult initialResult = ChristofidesWrapper.GetPathOptimizationResult(graph);
        graph.SetList((ArrayList<Nodes>)initialResult.nodes);

        if(conf.OptimizeResults()){
            if(conf.getTypeAlgoritmo()){
                SimulatedAnnealing.Setup(graph.list, conf.getIteraciones(), conf.getTemp(), conf.getAlfa(), conf.getTypeOperator());
                optimized = SimulatedAnnealing.OptimizePath();
            }
            else{
                HillClimbingB.Setup(graph.list, conf.getIteraciones(), conf.getTypeOperator()); //la lista de nodos de nodes
                optimized = HillClimbingB.OptimizePath();
            }
            graph.SetList((ArrayList<Nodes>) optimized.nodes);
        }
        graph.CalculateCost();
        return graph;
    }

	public Nodes optimizar_tarea(Nodes nodes_original) {
		HillClimbingB.Setup(nodes_original.nodelist); //la lista de nodos de nodes
        PathOptimizationResult optimized = HillClimbingB.OptimizePath();
        nodes_original.SetNodelist((ArrayList<Node>) optimized.nodes);
		return nodes_original;
	}
	public int recalcularCoste(Graph graph){
        int coste = 0;
		ArrayList<Integer> tour_inicial = OptimizationAlgorithm.DefaultTour(graph.list.size());
		coste = HillClimbFitnessCalculator.Calculate(tour_inicial, graph.list);
		return coste;
	}
}
